#define _CRT_SECURE_NO_WARNINGS 1

#include <stdio.h>

int main() {
    int n = 0;
    int m = 0;
    scanf("%d%d", &n, &m);
    char nm[n + 2][m + 2];

    int i = 0, j = 0;
    for (i = 0; i <= n + 1; i++)
    {
        for (j = 0; j <= m + 1; j++)
        {
            nm[i][j] = '0';
        }
    }
    for (i = 1; i <= n; i++)
    {
        for (j = 1; j <= m; j++)
        {
            scanf(" %c", &nm[i][j]);
        }
    }

    int count = 0;
    for (i = 1; i <= n; i++)
    {
        for (j = 1; j <= m; j++)
        {
            if (nm[i][j] == '*')
            {
                printf("%c", nm[i][j]);
                continue;
            }
            for (int q = -1; q <= 1; q++)
            {
                for (int w = -1; w <= 1; w++)
                {
                    if (q == 0 && w == 0)
                        continue;
                    if (nm[i + q][j + w] == '*')
                        count++;
                }
            }
            nm[i][j] = count + 48;
            count = 0;
            printf("%c", nm[i][j]);
        }
        printf("\n");
    }
    /*for(i = 0; i <= n + 1; i++)
    {
        for(j = 0; j <= m + 1; j++)
        {
            printf("%c",nm[i][j]);
        }
        printf("\n");
    }*/

    return 0;
}